<%--
  Created by IntelliJ IDEA.
  User: 86188
  Date: 2019/1/18
  Time: 10:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>初审信息</title>
    <script src="/static/js/jquery-3.3.1.js"></script>
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <script src="/static/layuiadmin/layui/layui.js" type="text/javascript"></script>
    <style>
        body {
            margin: 10px;
        }
    </style>
</head>
<body>
<div class="demoTable">
    <form id="myform" action="" method="post" class="layui-form">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">申请人:</label>
                <div class="layui-inline">
                    <input class="layui-input" name="cname" id="cname" placeholder="" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">手机号:</label>
                <div class="layui-inline">
                    <input class="layui-input" name="cphone" id="cphone" placeholder="" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">证件号:</label>
                <div class="layui-inline">
                    <input class="layui-input" name="cidentificationnumber" id="cidentificationnumber" placeholder="" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">申请流水号:</label>
                <div class="layui-inline">
                    <input class="layui-input" name="cpipeline" id="cpipeline" placeholder="" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">所属机构:</label>
                <div class="layui-inline">
                    <input class="layui-input" name="cmechanism" id="cmechanism" placeholder="" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">所属FA:</label>
                <div class="layui-inline">
                    <input class="layui-input" name="cfa" id="cfa" placeholder="" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">地址:</label>
                <div class="layui-inline">
                    <input class="layui-input" name="caddress" id="caddress" placeholder="" autocomplete="off">
                </div>
            </div>

        </div>
    </form>

    <div class="layui-form-item" style="margin-left: 980px;margin-top: -62px">
        <button class="layui-btn" data-type="reload" onclick="sear()">搜索</button>
        <button class="layui-btn" data-type="isExport">下载数据</button>
    </div>
</div>

<table class="layui-hide" id="demo" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="damage">审核</a>
</script>

<script>
    layui.use('table', function () {
        var params = {
            cname: $('#cname').val(),
            cphone: $('#cphone').val(),
            cidentificationnumber: $('#cidentificationnumber').val(),
            cpipeline: $('#cpipeline').val(),
            cmechanism: $('#cmechanism').val(),
            cfa: $('#cfa').val(),
            caddress: $('#caddress').val(),
            cstate: 1,
        };
        var table = layui.table;
        //执行一个 table 实例
        table.render({
            elem: '#demo',
            url: 'firstTrialList?name=' + encodeURIComponent(JSON.stringify(params)),   //数据接口,
            title: '',
            page: true,
            limit: 10,
            limits: [10, 20, 30, 40, 50],
            // toolbar: 'default', //开启工具栏，此处显示默认图标，可以自定义模板，详见文档,
            cols: [[ //表头
                {type: 'checkbox', fixed: 'left', align: 'center'}
                // , {field: 'cid', title: 'ID', sort: true, align: 'center'}
                , {type: 'numbers', title: '序号', align: 'center'}
                , {field: 'cpipeline', title: '申请流水号', sort: true, align: 'center'}
                , {field: 'ctime', title: '时间', sort: true, align: 'center'}
                , {field: 'cname', title: '申请人姓名', sort: true, align: 'center'}
                , {field: 'cphone', title: '联系电话', sort: true, align: 'center'}
                , {
                    field: 'cdocumenttype', title: '证件类型', align: 'center',
                    templet: function (c) {
                        if (c.cdocumenttype == 1) {
                            return "身份证";
                        } else if (c.cdocumenttype == 2) {
                            return "护照";
                        } else if (c.cdocumenttype == 3) {
                            return "港澳居民身份证";
                        } else if (c.cdocumenttype == 4) {
                            return "香港身份证";
                        }
                    }
                }
                , {field: 'cidentificationnumber', title: '证件号', align: 'center',}
                , {field: 'cmoney', title: '申报金额', align: 'center',}
                , {field: 'caddress', title: '地址', align: 'center',}
                , {field: 'cclaims', title: '债权包', align: 'center',}
                , {field: 'cmechanism', title: '所属机构', align: 'center',}
                , {field: 'cfa', title: 'FA', align: 'center',}
                , {field: 'cletters', title: '授信机构', align: 'center',}
                , {field: 'cproduct', title: '产品', align: 'center',}
                , {
                    field: 'cstate', title: '发布状态', align: 'center',
                    templet: function (s) {
                        if (s.cstate == 1) {
                            return "待初审";
                        } else if (s.cstate == 2) {
                            return "待调研";
                        } else if (s.cstate == 3) {
                            return "待复审";
                        } else if (s.cstate == 4) {
                            return "待授信";
                        } else if (s.cstate == 5) {
                            return "授信成功";
                        } else if (s.cstate == 6) {
                            return "授信失败";
                        }
                    }
                }
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#barDemo'}
            ]]
            , id: "reload"
        });
    });

    //查询方法
    function sear() {
        var params = {
            cname: $('#cname').val(),
            cphone: $('#cphone').val(),
            cidentificationnumber: $('#cidentificationnumber').val(),
            cpipeline: $('#cpipeline').val(),
            cmechanism: $('#cmechanism').val(),
            cfa: $('#cfa').val(),
            caddress: $('#caddress').val(),
            cstate: 1,
        };
        layui.use(['laypage', 'layer', 'table'], function () {
            var laydate = layui.laydate //日期
                , laypage = layui.laypage //分页
                , table = layui.table; //表格
            table.reload('reload', {
                url: 'firstTrialList?name=' + encodeURIComponent(JSON.stringify(params)) //数据接口
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });
    }

    layui.use(['form', 'laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
            , layer = layui.layer //弹层
            , table = layui.table //表格
            , carousel = layui.carousel //轮播
            , upload = layui.upload //上传
            , element = layui.element //元素操作
            , slider = layui.slider //滑块

        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'damage') {
                layer.open({
                    type: 2,
                    title: '进行审核',
                    maxmin: true,
                    shadeColse: true,//点击遮罩关闭层
                    area: ['500px', '400px'],
                    content: 'selectCreditByCid?cid=' + obj.data.cid,
                    end: function () {
                        //关闭窗口
                        table.reload('reload', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                    }
                });
            }
        });
    });
</script>

<script>

    layui.use('table', function () {
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(test)', function (obj) {
            console.log(obj)
        });

        var $ = layui.$, active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('reload')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            , getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('reload')
                    , data = checkStatus.data;
                layer.msg('选中了：' + data.length + ' 个');
            }
            , isAll: function () { //验证是否全选
                var checkStatus = table.checkStatus('reload');
                layer.msg(checkStatus.isAll ? '全选' : '未全选')
            }
            , isExport: function () {
                //获取选中数据
                var checkStatus = table.checkStatus('reload')
                    , data = checkStatus.data;
                var objs = eval(data);
                if (objs.length != null && "" != objs.length) {
                    layer.confirm('下载选中数据么', function (index) {
                        var cids = "";
                        for (var j = 0; j < objs.length; j++) {
                            if (j == 0) {
                                cids += objs[0].cid;
                            } else {
                                cids += "," + objs[j].cid;
                            }
                        }
                        layer.closeAll('dialog'); //关闭信息框
                        window.location.href = "isExport?cids=" + cids;
                    });
                } else {
                    layer.msg("未选中")
                }
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>